﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Text;
using MarvinsArena.Core;

namespace BattleEngineCommon
{
	public  class HudMessages:IHudMessages
	{
		private int messageStartPosition = 0;

		public SpriteFont FontSmall { get; set; }
		public SpriteFont Font { get; set; }

		public string StatusMessage { get; set; }
		public List<GameMessage> ListMessages{get; set;}
		public bool isStatusMessageActive { get; set; }

		public void DrawMessages(SpriteBatch spriteBatch)
		{
            messageStartPosition = spriteBatch.GraphicsDevice.Viewport.Height - 11 * 14;// 10 + 1 entries, 14 pixel each

            int i = messageStartPosition + (10 - ListMessages.Count) * 14;

			//Simple message
			foreach (GameMessage message in ListMessages)
			{
				Color color = Color.White;

				if (message.System)
					color = Color.Red;

				spriteBatch.DrawString(this.FontSmall, message.TextMessage, new Vector2(10, i), Color.White,
						0, new Vector2(), 1.0f, SpriteEffects.None, 0.5f);
				i += 14;
			}


			// Status message
			if (isStatusMessageActive)
			{
                Vector2 fontOriginStatusMessage = this.Font.MeasureString(this.StatusMessage) / 2;
                Vector2 centerScreen = new Vector2(spriteBatch.GraphicsDevice.Viewport.Width, spriteBatch.GraphicsDevice.Viewport.Height) / 2;

				spriteBatch.DrawString(this.Font, this.StatusMessage, centerScreen, Color.White,
					0, fontOriginStatusMessage, 1.0f, SpriteEffects.None, 0.5f);
			}
		}


		
	}
}
